package com.tsystems.school;

import java.util.HashMap;

import static java.lang.System.nanoTime;

/**
 * Created by IntelliJ IDEA.
 * User: victorn
 * Date: 8/14/11
 * Time: 12:27 AM
 * To change this template use File | Settings | File Templates.
 */
public class MyHashMapTest {

    public static void main(String[] args) {

        MyHashMap<String, Integer> mhm = new MyHashMap<String, Integer>();

        HashMap<String, Integer> shm = new HashMap<String, Integer>();

        int testCycle = 500000;

        long start;
        long end;

        String str[] = new String[testCycle];

        for (int i = 0; i < testCycle; i++)
            str[i] = String.valueOf(i);

        start = nanoTime();

        for (int i = 0; i < testCycle; i++) {
            mhm.put(str[i], i);
        }

        end = nanoTime() - start;

        System.out.println("mhm.put()");
        System.out.println((float) end / 1000000.0);

        start = nanoTime();

        for (int i = 0; i < testCycle; i++) {
            shm.put(str[i], i);
        }

        end = nanoTime() - start;

        System.out.println("\n shm.put()");
        System.out.println((float) end / 1000000.0);

        start = nanoTime();

        for (int i = 0; i < testCycle; i++) {
            //System.out.print(mhm.get(str[i]) + " ");
            mhm.get(str[i]);
        }

        end = nanoTime() - start;

        System.out.println("\n mhm.get()");
        System.out.println((float) end / 1000000.0);

        start = nanoTime();

        for (int i = 0; i < testCycle; i++) {
            //System.out.print(shm.get(str[i]) + " ")   ;
            shm.get(str[i]);
        }

        end = nanoTime() - start;

        System.out.println("\n shm.get()");

        System.out.println((float) end / 1000000.0);

        start = nanoTime();

        for (int i = 0; i < testCycle; i++) {
            System.out.print(mhm.remove(str[i]) + " ")   ;
            //mhm.remove(str[i]);
        }

        end = nanoTime() - start;
        System.out.println("\n mhm.remove()");
        System.out.println((float) end / 1000000.0);


        start = nanoTime();

        for (int i = 0; i < testCycle; i++) {
            //System.out.print(shm.get(str[i]) + " ")   ;
            shm.remove(str[i]);
        }

        end = nanoTime() - start;

        System.out.println("\n shm.remove()");
        System.out.println((float) end / 1000000.0);


        //System.out.println(mhm.containsKey("1"));

     /*   MyLinkedList<String, Integer> list = new MyLinkedList<String, Integer>();

        for (int i = 0; i < 20; i++) {
            System.out.print(list.put(String.valueOf(i % 10), i) + " ");
        }

        System.out.println();

        for (int i = 0; i < 20; i++) {
            if (list.get(String.valueOf(i)) != null)
                System.out.print(list.get(String.valueOf(i)) + " ");
        }

        System.out.println("\n" + list.size() + "\n");


        Entity<String, Integer> ent = new Entity<String, Integer>(10);

        for (int i = 0; i < 20; i++) {
            System.out.print(ent.add(String.valueOf(i % 10), i) + " ");
        }

        System.out.println();

        for (int i = 0; i < 20; i++) {

            if (ent.get(String.valueOf(i)) != null) {

                System.out.print(ent.get(String.valueOf(i)) + " ");
            }
        }

        System.out.println("\n" + ent.size() + "\n");
                                                                                             */
    }

}
